package com.card.manager.utils;

import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;

public class SerialGenerater {
	private static final Lock lock = new Lock();
	private static long last = 0;
	public static String generate(String pref){
		synchronized (lock) {
			try{
				if(last == System.currentTimeMillis())
					try {
						Thread.sleep(1);
					} catch (InterruptedException e) {
					}
				return pref + DateFormatUtils.format(new Date(),"yyyyMMddHHmmssSSS");
			}finally{
				last = System.currentTimeMillis();
			}
		}
	}
	public static String generate(){
		return generate("");
	}
	
	private static class Lock {
	}
}
